package com.oracle.sbdb.dao;

import org.apache.ibatis.session.SqlSession;

import com.oracle.sbdb.model.Product;

public class ProductDao {
	public Product selectbyId(int productId){
		SqlSession session = SessionFactory.getSession();
		Product res = session.selectOne("com.oracle.mybatis.ProductMapper.selectProduct", productId);
		session.commit();
		session.close();
		return res;
	}
	
	public int selectCount() {
		SqlSession session = SessionFactory.getSession();
		int res = session.selectOne("com.oracle.mybatis.ProductMapper.selectProductCount");
		session.commit();
		session.close();
		return res;
	}
	
	public void insert(Product Product) {
		SqlSession session = SessionFactory.getSession();
		session.selectOne("com.oracle.mybatis.ProductMapper.insertProduct", Product);
		session.commit();
		session.close();
	}
	
	public void update(Product Product) {
		SqlSession session = SessionFactory.getSession();
		session.selectOne("com.oracle.mybatis.ProductMapper.updateProduct", Product);
		session.commit();
		session.close();
	}
	
	public void delete(int productId) {
		SqlSession session = SessionFactory.getSession();
		session.selectOne("com.oracle.mybatis.ProductMapper.deleteProduct", productId);
		session.commit();
		session.close();
	}
}
